package org.jetnuke.modules.admin.content;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.Pages;
import org.jetnuke.util.JetUtil;

public class ContentUpdate implements IAction {
	int pid;

	String title, subtitle, page_header, text, page_footer;

	int active;

	int category;

	public void setActive(int active) {
		this.active = active;
	}

	public void setPage_header(String page_header) {
		this.page_header = page_header;
	}

	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		if (ai == null || (!ai.IsSuperUser() && !ai.isAdminContent()))
			return null;//Error;
		Pages page=DataAccessDriver.getInst().newPagesDAO().retrieveByPK(pid);
		//pages page = pagesPeer.retrieveByPK(pid);
		page.setPAGE_HEADER(page_header);
		page.setTEXT(text);
		page.setSUBTITLE(subtitle);
		page.setTITLE(title);
		page.setPAGE_FOOTER(page_footer);
		page.setACTIVE(active);
		page.setCID(category);
		DataAccessDriver.getInst().newPagesDAO().update(page);

		JetUtil.redirect(vc,response,request.getContextPath()+"/do/admin/content_manager");
		return null;
	}

	public String getPage_footer() {
		return page_footer;
	}

	public void setPage_footer(String page_footer) {
		this.page_footer = page_footer;
	}

	public int getCategory() {
		return category;
	}

	public void setCategory(int category) {
		this.category = category;
	}
}
